#ifndef __CONFIGURATION_H__
#define __CONFIGURATION_H__

#include <string>
#include <map>
#include <list>

class Configuration
{
public:
	void Add(const std::string& name, const std::string& value)
	{
		ConfigInfo[name].push_back(value);
	}

	class ConfigurationEntry
	{
	public:
		ConfigurationEntry(std::list<std::string>::const_iterator at, std::list<std::string>::const_iterator end)
			: At(at), End(end)
		{
		}

		const std::string& operator * () { return *At; }
		void operator ++ (int) { At++; }
		void operator ++ () { At++; }
		bool operator ()() { return At != End; }

	private:
		std::list<std::string>::const_iterator At, End;
	};

	std::string LookupSingle(const std::string& name) const
	{
		std::map<std::string,std::list<std::string>>::const_iterator it = ConfigInfo.find(name);
		if(it != ConfigInfo.end() && !it->second.empty())
			return *it->second.begin();
		return "";
	}

	std::list<std::string> LookupList(const std::string& name) const
	{
		std::map<std::string,std::list<std::string>>::const_iterator it = ConfigInfo.find(name);
		if(it != ConfigInfo.end())
			return it->second;
		std::list<std::string> junk;
		return junk;
	}

	ConfigurationEntry Lookup(const std::string& name) const
	{
		std::map<std::string,std::list<std::string>>::const_iterator it = ConfigInfo.find(name);
		if(it != ConfigInfo.end())
			return ConfigurationEntry(it->second.begin(), it->second.end());
		std::list<std::string> junk;
		return ConfigurationEntry(junk.end(), junk.end());
	}

private:
	std::map<std::string,std::list<std::string>> ConfigInfo;
};

#endif
